<?php

namespace app\api\controller\club;

use app\common\controller\ClubApi;

/**
 * 俱乐部小程序接口
 */
class Course extends ClubApi
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @api {get, post} /api/club/course/list 课程列表页面
     * @apiGroup 课程
     *
     * @apiParam {String} type 首页,列表
     */
    public function list($type='')
    {
        try{
            $data  = [];
            $data['list'] = $this->getService()->getCourseList($type);
            return $this->success('成功', $data);
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
    
    /**
     * @api {get, post} /api/club/course/history 历史课程列表页面
     * @apiGroup 课程
     *
     * @apiParam {String} category 分类
     */
    public function history($category='')
    {
        try{
            $data  = [];
            $data['list'] = $this->getService()->getCourseListHistory($category);
            return $this->success('成功', $data);
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
    
    /**
     * @api {get, post} /api/club/course/detail 课程详情页
     * @apiGroup 课程
     *
     * @apiParam {String} course_id 课程ID
     */
    public function detail($course_id='')
    {
        try{
            $data  = [];
            $data['detail'] = $this->getService()->getCourseDetail($course_id);
            return $this->success('成功', $data); 
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
    
    /**
     * @api {get, post} /api/club/course/listcomment 课程评论列表
     * @apiGroup 课程
     *
     * @apiParam {String} course_id 课程ID
     */
    public function listcomment($course_id='')
    {
        try{
            $data  = [];
            $data['list'] = $this->getService()->getCommentList($course_id, '课程');
            return $this->success('成功', $data);
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
    
    
    /**
     * @api {get, post} /api/club/course/comment 课程评论
     * @apiGroup 课程
     *
     * @apiParam {String} course_id 课程ID
     * @apiParam {String} text 评论内容
     */
    public function comment($text='', $course_id='')
    {
        try{
            if(!$text){
                throw new \Exception('评论内容不能为空');
            }
            $data  = [];
            $uid = $this->getService()->getLoginUid();
            $data['id'] = $this->getService()->getCourseAddComment($uid, $course_id, $text);
            return $this->success('成功', $data);
        } catch (\think\exception\HttpResponseException $e){
            throw $e;
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }
}
